
goog.require('goog.testing.jsunit');
goog.require('photographyPrize.Gallery');


var GalleryImageList = [
{
 'actor': {
  'image': {
   'url': 'https://lh6.googleusercontent.com/-4nvxivdKX9Y/AAAAAAAAAAI/AAAAAAAAAAA/mWvCcX6niOE/photo.jpg?sz=50'
  },
  'url': 'https://plus.google.com/100006436684891001954',
  'id': '100006436684891001954',
  'displayName': 'YÃªu Studio'
 },
 'published': '2011-11-25T10:35:18.771Z',
 'kind': 'plus#activity',
 'crosspostSource': '5614887801890749660',
 'object': {
  'plusoners': {
   'selfLink': 'https://www.googleapis.com/plus/v1/activities/z12qipupbuesifflp23ofd0y4ve0jzhel/people/plusoners'
  },
  'actor': {
   'image': {
    'url': 'https://lh6.googleusercontent.com/-4nvxivdKX9Y/AAAAAAAAAAI/AAAAAAAAAAA/mWvCcX6niOE/photo.jpg?sz=50'
   },
   'url': 'https://plus.google.com/100006436684891001954',
   'id': '100006436684891001954',
   'displayName': 'YÃªu Studio'
  },
  'replies': {
   'selfLink': 'https://www.googleapis.com/plus/v1/activities/z12qipupbuesifflp23ofd0y4ve0jzhel/comments'
  },
  'objectType': 'activity',
  'content': 'In game',
  'url': 'https://plus.google.com/100006436684891001954/posts/6LQXC74Xkhq',
  'id': 'z12qi344plvmetwkz23ofd0y4ve0jzhel',
  'resharers': {
   'selfLink': 'https://www.googleapis.com/plus/v1/activities/z12qipupbuesifflp23ofd0y4ve0jzhel/people/resharers'
  },
  'attachments': [
   {
    'objectType': 'photo-album',
    'url': 'https://plus.google.com/photos/100006436684891001954/albums/5678873488525224353',
    'displayName': 'football in the village  (1 photo)'
   },
   {
    'image': {
     'height': 85,
     'width': 128,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh4.googleusercontent.com%2F-hWrE1Y3ZZD0%2FTs9pWbKfQvI%2FAAAAAAAAAA4%2FddQkC02pn8I%2Fw128-h85%2FCopa%252BLa%2525CC%252580ng%252BCha%2525CC%252580i%252Bcopy.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1365,
     'width': 2048,
     'url': 'https://lh4.googleusercontent.com/-hWrE1Y3ZZD0/Ts9pWbKfQvI/AAAAAAAAAA4/ddQkC02pn8I/s0-d/Copa%2BLa%25CC%2580ng%2BCha%25CC%2580i%2Bcopy.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'Copa LaÌ€ng ChaÌ€i copy.jpg',
    'url': 'https://plus.google.com/photos/100006436684891001954/albums/5678873488525224353/5678873489107272434'
   }
  ]
 },
 'updated': '2011-11-25T10:35:18.771Z',
 'url': 'https://plus.google.com/100006436684891001954/posts/9viLtDA2uQo',
 'access': {
  'items': [
   {
    'type': 'public'
   }
  ],
  'kind': 'plus#acl'
 },
 'id': 'z12qipupbuesifflp23ofd0y4ve0jzhel',
 'title': 'Reshared post from YÃªu Studio\n \n\nIn game',
 'annotation': '#sportgpp',
 'provider': {
  'title': 'Google+'
 },
 'verb': 'share'
},

{
 'actor': {
  'image': {
   'url': 'https://lh6.googleusercontent.com/-89fKX89DIqY/AAAAAAAAAAI/AAAAAAAAAAA/P2s2jP_Xd5g/photo.jpg?sz=50'
  },
  'url': 'https://plus.google.com/105138199454397530017',
  'id': '105138199454397530017',
  'displayName': 'Moustapha Baghdadi'
 },
 'published': '2011-11-25T09:00:53.000Z',
 'kind': 'plus#activity',
 'crosspostSource': 'oz:105138199454397530017.133d9f34ee7.0',
 'object': {
  'plusoners': {
   'selfLink': 'https://www.googleapis.com/plus/v1/activities/z135cbdqpvihfnmvp22mejxjllztffwwj04/people/plusoners',
   'totalItems': 1
  },
  'replies': {
   'selfLink': 'https://www.googleapis.com/plus/v1/activities/z135cbdqpvihfnmvp22mejxjllztffwwj04/comments'
  },
  'objectType': 'note',
  'content': '#travelgpp',
  'url': 'https://plus.google.com/105138199454397530017/posts/LfmMfGxFBkd',
  'resharers': {
   'selfLink': 'https://www.googleapis.com/plus/v1/activities/z135cbdqpvihfnmvp22mejxjllztffwwj04/people/resharers'
  },
  'originalContent': '#travelgpp',
  'attachments': [
   {
    'image': {
     'height': 96,
     'width': 64,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh6.googleusercontent.com%2F-1wW3gTiTt-k%2FTs9VuAhmpAI%2FAAAAAAAAAGM%2F2mH_x-XVY8g%2Fs128%2FIMG_0640_1_2_fused.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1600,
     'width': 1069,
     'url': 'https://lh6.googleusercontent.com/-1wW3gTiTt-k/Ts9VuAhmpAI/AAAAAAAAAGM/2mH_x-XVY8g/IMG_0640_1_2_fused.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_0640_1_2_fused.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678851904040772610',
    'displayName': '#travelgpp - Blue Mosque (Sultan Ahmet Cameii) - Istanbul, Turkey'
   },
   {
    'objectType': 'photo-album',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481',
    'displayName': 'Google Photography Prize (8 photos)'
   },
   {
    'image': {
     'height': 84,
     'width': 128,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh6.googleusercontent.com%2F-p0UI_TsR_uk%2FTs9W43pPcwI%2FAAAAAAAAAGw%2FBvpEU-bt64U%2Fs128%2FIMG_0720_1_2.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1050,
     'width': 1600,
     'url': 'https://lh6.googleusercontent.com/-p0UI_TsR_uk/Ts9W43pPcwI/AAAAAAAAAGw/BvpEU-bt64U/IMG_0720_1_2.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_0720_1_2.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678853190147076866',
    'displayName': '#travelgpp - AyaSofya,Istanbul, Turkey'
   },
   {
    'image': {
     'height': 96,
     'width': 128,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh6.googleusercontent.com%2F-oty3N-uirAU%2FTs9USRHZVXI%2FAAAAAAAAAF8%2FrwKZQKr0ZO4%2Fs128%2FIMG_3858.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1200,
     'width': 1600,
     'url': 'https://lh6.googleusercontent.com/-oty3N-uirAU/Ts9USRHZVXI/AAAAAAAAAF8/rwKZQKr0ZO4/IMG_3858.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_3858.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678850327946286450',
    'displayName': '#travelgpp - Hafez Tomb, Shiraz, Iran'
   },
   {
    'image': {
     'height': 96,
     'width': 72,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh5.googleusercontent.com%2F-0hl39nIlv4s%2FTs9VdhIzZZI%2FAAAAAAAAAGE%2F8IJn5MA045A%2Fs128%2FIMG_7011-e.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1600,
     'width': 1200,
     'url': 'https://lh5.googleusercontent.com/-0hl39nIlv4s/Ts9VdhIzZZI/AAAAAAAAAGE/8IJn5MA045A/IMG_7011-e.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_7011-e.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678851620737344914',
    'displayName': '#travelgpp - Echmiadzin Church - Armenia'
   },
   {
    'image': {
     'height': 89,
     'width': 128,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh6.googleusercontent.com%2F-DSyqpu7yOGk%2FTs9WbjlkBqI%2FAAAAAAAAAGc%2FxUx7qFXwM2k%2Fs128%2FIMG_7208.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1115,
     'width': 1600,
     'url': 'https://lh6.googleusercontent.com/-DSyqpu7yOGk/Ts9WbjlkBqI/AAAAAAAAAGc/xUx7qFXwM2k/IMG_7208.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_7208.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678852686546732706',
    'displayName': '#travelgpp - Saint Gregory the Illuminator Church in Yerevan, Armenia'
   },
   {
    'image': {
     'height': 96,
     'width': 75,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh3.googleusercontent.com%2F-A_khanzKBbU%2FTs9XMJv_c0I%2FAAAAAAAAAG8%2FB19acrklSnA%2Fs128%2FIMG_7300.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1600,
     'width': 1265,
     'url': 'https://lh3.googleusercontent.com/-A_khanzKBbU/Ts9XMJv_c0I/AAAAAAAAAG8/B19acrklSnA/IMG_7300.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_7300.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678853521424741186',
    'displayName': '#travelgpp - Ararat, Sis Mount, Armenia'
   },
   {
    'image': {
     'height': 96,
     'width': 128,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh3.googleusercontent.com%2F-cDt2__-mJPk%2FTs9XTvgx-0I%2FAAAAAAAAAHI%2Fiw2cPsDHE5Y%2Fs128%2FIMG_7405-e.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1200,
     'width': 1600,
     'url': 'https://lh3.googleusercontent.com/-cDt2__-mJPk/Ts9XTvgx-0I/AAAAAAAAAHI/iw2cPsDHE5Y/IMG_7405-e.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_7405-e.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678853651820575554',
    'displayName': '#travelgpp - Garni Temple, Armenia'
   },
   {
    'image': {
     'height': 85,
     'width': 128,
     'url': 'http://images0-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&resize_h=100&url=https%3A%2F%2Flh4.googleusercontent.com%2F-RFYElu18JDg%2FTs9Yw9-BuGI%2FAAAAAAAAAHs%2FzF9pZG6MfQA%2Fs128%2FIMG_9048_7_6.jpg',
     'type': 'image/jpeg'
    },
    'fullImage': {
     'height': 1065,
     'width': 1600,
     'url': 'https://lh4.googleusercontent.com/-RFYElu18JDg/Ts9Yw9-BuGI/AAAAAAAAAHs/zF9pZG6MfQA/IMG_9048_7_6.jpg',
     'type': 'image/jpeg'
    },
    'objectType': 'photo',
    'content': 'IMG_9048_7_6.jpg',
    'url': 'https://plus.google.com/photos/105138199454397530017/albums/5678850323825132481/5678855253429172322',
    'displayName': '#travelgpp -  Kuala Lumpur View At sunset, Malaysia'
   }
  ]
 },
 'updated': '2011-11-25T09:00:54.096Z',
 'url': 'https://plus.google.com/105138199454397530017/posts/LfmMfGxFBkd',
 'access': {
  'items': [
   {
    'type': 'public'
   }
  ],
  'kind': 'plus#acl'
 },
 'id': 'z135cbdqpvihfnmvp22mejxjllztffwwj04',
 'title': '#travelgpp',
 'provider': {
  'title': 'Google+'
 },
 'verb': 'post'
}
];


var gallery = null;
var galleryElement = null;


window.gapi = {plusone: {go: function(images) {
  assert(images != null);
}}};


function setUpPage() {
  galleryElement = goog.dom.createDom('div');
  document.body.appendChild(galleryElement);
  gallery = new photographyPrize.Gallery(galleryElement);
}


function tearDownPage() {
  gallery.dispose();
  document.body.removeChild(galleryElement);
}


function testphotographyPrize$Gallery() {
  var galleryElement = goog.dom.createDom('div');
  document.body.appendChild(galleryElement);
  assertEquals(0, galleryElement.childNodes.length);
  var gallery = new photographyPrize.Gallery(galleryElement);
  assertEquals(galleryElement, gallery.containerElement_);
  assertEquals(document.body, galleryElement.parentNode);
  assertEquals(3, galleryElement.childNodes.length);
  gallery.dispose();
  document.body.removeChild(galleryElement);
}


function testdispose() {
  var galleryElement = goog.dom.createDom('div');
  document.body.appendChild(galleryElement);
  assertEquals(0, galleryElement.childNodes.length);
  var gallery = new photographyPrize.Gallery(galleryElement);
  gallery.dispose();
  assertEquals(document.body, galleryElement.parentNode);
  assertEquals(0, galleryElement.childNodes.length);
  document.body.removeChild(galleryElement);
}


function testphotographyPrize$Gallery$Categories() {
  assert(photographyPrize.Gallery.Categories != null);
  assert(photographyPrize.Gallery.Categories.length > 0);
  assert(photographyPrize.Gallery.Categories[0].tag != null);
  assert(photographyPrize.Gallery.Categories[0].name != null);
}


function testConstants() {
  assertEquals('string', typeof photographyPrize.Gallery.IMAGE_LIST_URL);
  assertEquals('string', typeof photographyPrize.Gallery.MSG_VIEW_ALBUM);
  assertEquals('string', typeof photographyPrize.Gallery.MSG_THE_END);
  assertEquals('string',
               typeof photographyPrize.Gallery.MSG_MAX_IMAGES_REACHED);
  assertEquals('string', typeof photographyPrize.Gallery.MSG_NO_IMAGES);
  assertEquals('number', typeof photographyPrize.Gallery.MAX_IMAGE_COUNT);
  assertEquals('number', typeof photographyPrize.Gallery.INITIAL_LOAD_COUNT);
  assertEquals('number', typeof photographyPrize.Gallery.SCROLL_LOAD_COUNT);
  assertEquals('number', typeof photographyPrize.Gallery.MAX_IMAGE_SIZE);
}


function testCreateGallery_() {
  var cat = gallery.categories_[0];
  assertEquals(cat.tag, photographyPrize.Gallery.Categories[0].tag);
  assertEquals(cat.name, photographyPrize.Gallery.Categories[0].name);
  assertEquals(cat, gallery.categoryIndex_[gallery.getCategoryFragment_(cat)]);
  assert(gallery.getCategoryLink_(cat) != null);
  assert(gallery.getCategoryLink_(cat) !=
         gallery.getCategoryLink_(gallery.categories_[1]));
}


function testGetCategoryLink_() {
  assert(null != gallery.getCategoryLink_(gallery.categories_[0]));
  assertEquals(undefined, gallery.getCategoryLink_({tag: 'foo', name: 'bar'}));
}


function testSetCategoryLink_() {
  gallery.setCategoryLink_({tag: 'boz', name: 'foz'}, 123);
  assertEquals(123, gallery.getCategoryLink_({tag: 'boz', name: 'foz'}));
}


function testLoadImages_() {
  gallery.loadImages_('foo', 10, 0, function(e) {});
  gallery.clearGallery_();
}


function testDisplayImages_() {
  gallery.displayImages_([]);
  gallery.clearGallery_();
  var c = gallery.galleryElement_.childNodes.length;
  gallery.displayImages_(GalleryImageList);
  var c2 = gallery.galleryElement_.childNodes.length;
  assertEquals(c + 1, c2);
  assertEquals(2, gallery.galleryElement_.lastChild.childNodes.length);
  assertThrows(function() {gallery.displayImages_(null);});
}


function testCreateCategoryLink_() {
  var link = gallery.createCategoryLink_({tag: 'foozi', name: 'bar & bar'});
  assertEquals('barbar-button', link.id);
  assertEquals('#barbar', link.getAttribute('href'));
  assertEquals('bar & bar', goog.dom.getTextContent(link));
  if (link.fireEvent) {
    link.fireEvent('onclick');
  } else {
    var evt = document.createEvent("MouseEvents");
    evt.initMouseEvent("click", true, true, window,
                       0, 0, 0, 0, 0, false, false, false, false, 0, null);
    link.dispatchEvent(evt);
  }
  assertEquals(link.getAttribute('href'), document.location.hash);
}


function testGetCategoryFragment_() {
  assertEquals('barbar',
      gallery.getCategoryFragment_({tag: 'foo', name: 'bar & bar/!'}));
  assertEquals('barderp123',
      gallery.getCategoryFragment_({tag: 'foo', name: 'barDerp123/!'}));
  assertThrows(function() {gallery.getCategoryFragment_();});
  assertThrows(function() {gallery.getCategoryFragment_('blaat');});
  assertThrows(function() {gallery.getCategoryFragment_({name: 123});});
  assertThrows(function() {gallery.getCategoryFragment_({tag: 'foo'});});
}


function testLoadCategory_() {
  gallery.loadCategory_(gallery.categories_[0]);
  assertEquals('#' + gallery.getCategoryFragment_(gallery.categories_[0]),
               document.location.hash);
  gallery.loadCategory_({name: 'foo', tag: 'bar'});
  assertEquals('#foo', document.location.hash);
  assertThrows(function() { gallery.loadCategory_(123); });
  assertThrows(function() { gallery.loadCategory_(null); });
}


function testClearGallery_() {
  gallery.showEndMessage_('HELLO');
  assertNotEquals(0, gallery.galleryElement_.childNodes.length);
  gallery.clearGallery_();
  assertEquals(0, gallery.galleryElement_.childNodes.length);
}


function testShowSpinner_() {
  gallery.hideSpinner_();
  assertEquals('none', gallery.spinnerElement_.style.display);
  gallery.showSpinner_();
  assertEquals('', gallery.spinnerElement_.style.display);
}


function testHideSpinner_() {
  gallery.showSpinner_();
  assertEquals('', gallery.spinnerElement_.style.display);
  gallery.hideSpinner_();
  assertEquals('none', gallery.spinnerElement_.style.display);
}


function testLoadImageList_() {
  gallery.hideSpinner_();
  assertEquals('none', gallery.spinnerElement_.style.display);
  gallery.loadImageList_({tag: 'foo', name: 'bar'}, 10, 10);
  assertEquals('', gallery.spinnerElement_.style.display);
  assertThrows(function() {
    gallery.loadImageList_(null, 10, 10);
  });
}


function testLoadImagesHandler_() {
  gallery.hideSpinner_();

  gallery.loadCategory_({tag: 'foo', name: 'bar'});
  assertEquals('', gallery.spinnerElement_.style.display);
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 0, []);
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertEquals(photographyPrize.Gallery.MSG_NO_IMAGES,
               goog.dom.getTextContent(gallery.galleryElement_));
  assertEquals('none', gallery.spinnerElement_.style.display);

  gallery.loadCategory_({tag: 'foo', name: 'bar'});
  assertEquals('', gallery.spinnerElement_.style.display);
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 0, [null]);
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertEquals(photographyPrize.Gallery.MSG_NO_IMAGES,
               goog.dom.getTextContent(gallery.galleryElement_));
  assertEquals('none', gallery.spinnerElement_.style.display);

  gallery.loadCategory_({tag: 'foo', name: 'bar'});
  var c = gallery.galleryElement_.childNodes.length;
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 0, GalleryImageList);
  var c2 = gallery.galleryElement_.childNodes.length;
  assertEquals(c + 2, c2);
  assertEquals(2, gallery.galleryElement_.firstChild.childNodes.length);

  gallery.loadCategory_({tag: 'foo', name: 'bar'});
  c = gallery.galleryElement_.childNodes.length;
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 0, 
                             GalleryImageList.concat([null]));
  c2 = gallery.galleryElement_.childNodes.length;
  assertEquals(c + 2, c2);
  assertEquals(2, gallery.galleryElement_.firstChild.childNodes.length);

  gallery.loadCategory_({tag: 'foo', name: 'bar'});
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 1, []);
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertEquals(photographyPrize.Gallery.MSG_THE_END,
               goog.dom.getTextContent(gallery.galleryElement_));
}


function testShowEndMessage_() {
  gallery.clearGallery_();
  assertEquals(0, gallery.galleryElement_.childNodes.length);
  gallery.showEndMessage_('HELLO');
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertEquals('HELLO', goog.dom.getTextContent(gallery.galleryElement_));
  gallery.showEndMessage_("this shouldn't show up");
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertEquals('HELLO', goog.dom.getTextContent(gallery.galleryElement_));
}


function testHandleScroll_() {
  // don't know how to test scrolling
  gallery.handleScroll_();
}


function testTryLoadingNextImages_() {
  photographyPrize.Gallery.MAX_IMAGE_COUNT = 1;
  gallery.clearGallery_();
  assertEquals(0, gallery.galleryElement_.childNodes.length);
  gallery.currentOffset_ = 2;
  gallery.loadedOffset_ = 2;
  gallery.tryLoadingNextImages_();
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertEquals(photographyPrize.Gallery.MSG_MAX_IMAGES_REACHED,
               goog.dom.getTextContent(gallery.galleryElement_.lastChild));

  photographyPrize.Gallery.MAX_IMAGE_COUNT = 10;
  gallery.clearGallery_();
  assertEquals(0, gallery.galleryElement_.childNodes.length);
  gallery.currentOffset_ = 0;
  gallery.loadedOffset_ = 0;
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 0, GalleryImageList);
  gallery.tryLoadingNextImages_();
  assertEquals(2, gallery.galleryElement_.childNodes.length);
  assertEquals(photographyPrize.Gallery.MSG_THE_END,
               goog.dom.getTextContent(gallery.galleryElement_.lastChild));

  photographyPrize.Gallery.MAX_IMAGE_COUNT = 10;
  gallery.clearGallery_();
  assertEquals(0, gallery.galleryElement_.childNodes.length);
  gallery.currentOffset_ = 2;
  gallery.loadedOffset_ = 0;
  gallery.loadImagesHandler_({tag: 'foo', name: 'bar'}, 0, GalleryImageList);
  gallery.tryLoadingNextImages_();
  assertEquals(1, gallery.galleryElement_.childNodes.length);
  assertNotEquals(photographyPrize.Gallery.MSG_MAX_IMAGES_REACHED,
                  goog.dom.getTextContent(gallery.galleryElement_.lastChild));
}
